class Command {
    public constructor(
        public Name: string = "",
        public Action: Function = new Function()
    ) { };
}

function Log(
    target: any,
    propertyKey: string | symbol,
    descriptor: PropertyDescriptor
) {
    // descriptor.value 是 被修饰的原方法
    let originalMethod = descriptor.value;

    // 修改被修饰原方法 的 部分实现方式
    descriptor.value = function () {
        console.log("尝试添加命令:", arguments[0].Name);
        originalMethod.apply(this, arguments);
    };
    // 返回修改后的方法
    return descriptor;
}

class CommandCollection {
    private readonly collection: Map<string, Command>;
    constructor() {
        this.collection = new Map<string, Command>();
    }

    @Log
    public Add(command: Command): void {
        if (!this.collection.has(command.Name)) {
            this.collection.set(command.Name, command)
        }
        else {
            console.log("命令已存在 !")
        }
    }

    public Get(name: string): Command | undefined {
        return this.collection.get(name);
    }
}

let cmdCollection = new CommandCollection();
cmdCollection.Add(new Command("Test"));
cmdCollection.Add(new Command("Test"));
console.log(cmdCollection.Get("Test"));
